<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.rbcs.base.company.CompanyHelp" %>
<%@include file="/common/taglibs.jsp" %>
<html>
<head>
<base target="_self">
<%@include file="/common/meta.jsp" %>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/ec.jsp" %>
<link href="${ctx}/styles/treeSelect.css" type='text/css' rel='stylesheet'>
</head>
<body>
<script type="text/javascript">
/**
 * 提交表单
 */
function submitForm(){
	$("#queryForm").submit();
}
</script>
<div class="x-panel">
  <div class="x-toolbar">
    <form id="queryForm" action="selectUserIndex.do" method="post">
	    <table width="100%" style="line-height: 25px; height: 30px;">  
	      <tr>
	      	<td>&nbsp;部门：</td>
	      	<td>
	      	 <div id="comboxWithTree"></div>
	         <input type="hidden" id="deptId" name="model.dept.id" value="${model.dept.id}"/>
	      	</td>
	        <td>&nbsp;姓名：</td>
	        <td>&nbsp;<s:textfield id="userName" name="model.name" size="12" cssStyle="height:22px; padding:2px 1px;"/></td>
	        <td>&nbsp;<s:submit value="查询" cssClass="button" /></td>
	      </tr>
	    </table>
    </form>
  </div> 
  <div>
	<ec:table items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit" 
		action="selectUserIndex.do"
		useAjax="true" doPreload="false"
		maxRowsExported="10000000" 
		pageSizeList="500,ALL" 
		editable="false" 
		sortable="false"	
		rowsDisplayed="500"	
		generateScript="true"	
		resizeColWidth="false"	
		classic="false"	
		width="100%" 	
		height="310px"	
		minHeight="310"
		toolbarContent="navigation|pagejump|pagesize|refresh|extend|status"   >
		<ec:row>
		    <ec:column width="40" property="_s" title="选择" sortable="false" style="text-align:center">
		    	<input type="checkbox" name="selectedItems" id="selectedItems" value="${item.id}" title="${item.name}" class="checkbox" onclick="checkUser(this)"/>
		    </ec:column>
			<ec:column width="120" property="name" title="姓名" />
			<ec:column width="140" property="dept.name" title="部门" />
			<ec:column width="80" property="type" title="用户类别" mappingItem="typeMap" style="text-align:center;"/>
			<ec:column width="120" property="mobile" title="手机" />
		</ec:row>
	</ec:table>
  </div>
  <div align="center" style="margin: 5px;">
    <input type="button" class="button" value="保存已选择用户" style="font-weight:bold;" onclick="returnSelectValue()">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" class="button" value="关闭" style="font-weight:bold;" onclick="window.close();">
  </div>
</div>
<s:hidden id="selectedUserIds" />
<s:hidden id="selectedUserNames" />
  <script type="text/javascript" src="${ctx}/pages/admin/dept/edit.js"></script>
  <script type="text/javascript">
	  var rootName = '<%=CompanyHelp.getComName()%>';
	  var initValue = '${model.dept.name}';
	  if (initValue.length == 0){
	  	initValue = rootName;
	  }
	  Ext.onReady(function() {
	  	var dtree = new DeptTree({
	  		url : '/admin/dept/deptTree.do',
	  		rootName: rootName,
	  		initValue : initValue,
	  		el : 'comboxWithTree',
	  		innerTree :'inner-tree',
	  		onclick : function(nodeId) {
	  		  Ext.get('deptId').dom.value = nodeId;
	  		}
	  	});
	  	dtree.init();	
	  });
	  
	  var spliteStr = ",";
	  function checkUser(obj){
		  var selectedUserIds = $("#selectedUserIds").val();
		  var selectedUserNames =  $("#selectedUserNames").val();
		  if (obj.checked){
			selectedUserIds = selectedUserIds + obj.value + spliteStr;
			selectedUserNames = selectedUserNames + obj.title + spliteStr;
		  }else{
			selectedUserIds = selectedUserIds.replace((obj.value + spliteStr), '');
			selectedUserNames = selectedUserNames.replace((obj.title + spliteStr), '');
		  }
		  $("#selectedUserIds").val(selectedUserIds);
		  $("#selectedUserNames").val(selectedUserNames);
	  }

		//关闭窗口，返回数据
		function returnSelectValue(){
			var user = new Object();
			user.ids =  $("#selectedUserIds").val();
			user.names =  $("#selectedUserNames").val();
			window.returnValue = user;
			window.close();
		}
  </script>
</body>
</html>